package qingke.bean;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import qingke.mybatis.pojo.Store;
import qingke.mybatis.pojo.User;

public class CartOfProduct implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5868900451101201265L;

	private User user;

	private Store store;

	Map<Integer, Integer> productmap = new HashMap<>();

	private int amount = 0;

	public CartOfProduct() {

	}

	public CartOfProduct(User user, Store store) {
		this.user = user;
		this.store = store;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public int getAmount() {
		this.amount = 0;
		Iterator<Entry<Integer, Integer>> iter = productmap.entrySet().iterator();
		while (iter.hasNext()) {
			Entry<Integer, Integer> entry = (Entry<Integer, Integer>) iter.next();
			this.amount += (int) entry.getValue();
		}
		return amount;
	}

	public Map<Integer, Integer> getProductmap() {
		return productmap;
	}

	public void addProductmap(Integer priductId, Integer number) {
		this.productmap.put(priductId, number);
	}

	public void setProductmap(Map<Integer, Integer> productmap) {
		this.productmap = productmap;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public Store getStore() {
		return store;
	}

	public void setStore(Store store) {
		this.store = store;
	}

	@Override
	public String toString() {
		return "CartOfProduct [user=" + user + ", productmap=" + productmap + ", amount=" + amount + "]";
	}

}
